package org.example.maven.museumuser.controller;

import org.example.maven.museumuser.domain.pojo.Result;
import org.example.maven.museumuser.domain.pojo.action.ActionOrder;
import org.example.maven.museumuser.service.IActionService;
import org.example.maven.museumuser.service.IActionTicketUserService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zafkiel
 * @since 2025-06-21
 */
@RestController
@RequestMapping("/action")
public class ActionController {
    @Autowired
    private IActionService iActionService;
    @Autowired
    private IActionTicketUserService iActionTicketUserService;


    @GetMapping(("/list"))
    @PreAuthorize("permitAll()")
    //获取活动的list数据
    public Result getAllActions() {
        return Result.success("获取活动操作成功",iActionService.getaAllActionlist());
    }

    //根据id获取活动数据
    @GetMapping("/{id}")
    @PreAuthorize("permitAll()")
    public Result getActionById(@PathVariable Integer id) {
        return Result.success("获取活动操作成功",iActionService.getActionDetailsById(id));
    }

    //进行活动报名
    @PostMapping("/signUp")
    @PreAuthorize("permitAll()")
    public Result signUp(@RequestBody ActionOrder actionOrder) throws InterruptedException {
        return iActionTicketUserService.saveActionOrder(actionOrder);
    }

}
